#!/bin/bash

   set -e

#指定特定的路径
  function path()
 {
   read -p "输入目录名称：" code_path
   if [ -d ${code_path} ]; then
    code_path=${code_path}_tmp
    if [ -d ${code_path} ]; then
      rm -rf ${code_path:?}
    fi
  fi
  mkdir ${code_path}
  
 }
 
 
 #输出菜单信息函数
   function print_menu()
  {
 
  echo -e " ******************************************* "
  echo -e " * Welcome to download OpenHarmony Code 	  * "
  echo -e " * Please Choice OpenHarmony SDK:	        * "
  echo -e " * OpenHarmony Version             	      * "
  echo -e " * OpenHarmony master       	prese 1.1     * "
  echo -e " * OpenHarmony-3.2-beta2    	press 1.2     * "
  echo -e " * OpenHarmony-3.2-beta2-merge press 1.3   * "
  echo -e " * OpenHarmony-3.2-release  	press 1.4     * "
  echo -e " ******************************************* "
  
  }
   
     

 #输出菜单信息
  print_menu
  
  url="https://gitee.com/openharmony/manifest.git"
  xml_name="default.xml"
  sync_cmd="repo sync -c "
  lfs_br_cmd="repo forall -c 'git lfs pull' "
  
  while :
  do
 #输入要下载的代码命令
   read -p "请输入下载代码命令参数：" command

 #下载“OpenHarmony master ”代码
   if [[ ${command} = 1.1 ]];then
   path
       echo 
   "
   you have been download OpenHarmony master  code
   url       : $url
   branch    : OpenHarmony master 
   xml_name  : $xml_name
   code_path : $(pwd)/${code_path}
   init   cmd: repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify
   sync   cmd: $sync_cmd
   lfs    cmd: $lfs_br_cmd
   set_br cmd: repo start master --all 
   "
       break
 
 #下载“OpenHarmony-3.2-beta2”代码
   elif [[ ${command} = 1.2 ]];then
   path
       echo
   "
   you have been download OpenHarmony-3.2-beta2
   url       : $url
   branch    : OpenHarmony-3.2-beta2
   xml_name  : $xml_name
   code_path : $(pwd)/${code_path}
   init   cmd: repo init -u https://gitee.com/openharmony/manifest -b OpenHarmony-3.2-Beta2 --no-repo-verify
   sync   cmd: $sync_cmd
   lfs    cmd: $lfs_br_cmd
   set_br cmd: repo start OpenHarmony-3.2-Beta2 --all
   "
       break

 #下载“OpenHarmony-3.2-beta2-merge”代码
   elif [[ ${command} = 1.3 ]];then
   path
       echo 
   "
   you have been download OpenHarmony-3.2-beta2-merge  code
   url       : $url
   branch    : OpenHarmony-3.2-beta2-merge 
   xml_name  : $xml_name
   code_path : $(pwd)/${code_path}
   init   cmd: repo init -u https://gitee.com/openharmony/manifest -b OpenHarmony-3.2-beta2-Merge -m thead_develop.xml --no-repo-verify
   sync   cmd: $sync_cmd
   lfs    cmd: $lfs_br_cmd
   set_br cmd: repo start OpenHarmony-3.2-beta2 --all
   "
       break

 #下载“OpenHarmony-3.2-release”代码
   elif [[ ${command} = 1.4 ]];then
   path
       echo 
   "
   you have been download  OpenHarmony-3.2-release  code
   url       : $url
   branch    : OpenHarmony-3.2-beta2-merge 
   xml_name  : $xml_name
   code_path : $(pwd)/${code_path}
   init   cmd: repo init -u https://gitee.com/openharmony/manifest -b OpenHarmony-3.2-Release -m default.xml --no-repo-verify
   sync   cmd: $sync_cmd
   lfs    cmd: $lfs_br_cmd
   set_br cmd: repo start  OpenHarmony-3.2-Release --all
   "
       break

 #如果输入不带参数，则会打印出menu菜单要求选择某个分支
   elif [[ ${command} = "" ]];then
       print_menu
 #如果输入的参数不对，则会输出错误信息，并打印出menu菜单要求选择某个分支
  else
      echo "product is not in product list, please recheck!!!"
      print_menu
   fi
  done


